﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace Golos.Polls.PollCache
{
    [Serializable]
    public class AnswerProperties
    {
        public Guid AnswerId { get; private set; }
        public string Ip { get; private set; }
        public bool Sex { get; private set; }

        public AnswerProperties(Guid answerId, string ip, bool sex)
        {
            AnswerId = answerId;
            Ip = ip;
            Sex = sex;
        }

        public byte[] Serialize()
        {
            MemoryStream stream = new MemoryStream();
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.Serialize(stream, this);
            stream.Close();
            return stream.ToArray();
        }

        public static AnswerProperties Deserialize(Stream stream)
        {
            BinaryFormatter bFormatter = new BinaryFormatter();
            AnswerProperties answerProperties = (AnswerProperties)bFormatter.Deserialize(stream);
            stream.Close();
            return answerProperties;
        }
    }
}
